package com.jketing.shiro.factory;

import java.util.LinkedHashMap;

public class FilterChainDefinitionMapBuilder {

	public LinkedHashMap<String, String> buildFilterChainDefinitionMap(){
		LinkedHashMap<String, String> map = new LinkedHashMap<>();
		map.put("/login.jsp", "anon");
		map.put("/index.jsp", "anon");
		map.put("/ClientLogin", "anon");
		map.put("/login", "anon");
		map.put("/res/**", "anon");
		map.put("/scripts/**", "anon");
		map.put("/Themes/**", "anon");
		map.put("/shiro/logout", "logout");
		/*List<Function> funList = functionService.findByUseable("true");
		List<Operation> butList = operationService.findAll();
		for(Function fun:funList) {
			if("3".equals(fun.getFunType().trim())) {
				String url = "/" + fun.getStamp().trim();
				String mark = fun.getStamp().trim() + ":";
				switch(fun.getParent().getStamp().trim()) {
					case "form":
					case "workflow":
						String key = url + "/**";
						String value = "authc,roles[developer]";
						map.put(key, value);
						break;
					case "sys":
						if("account".equals(fun.getStamp().trim())) {
							for(Operation item:butList) {
								key = url;
								value = mark;
								if(!"button".equals(item.getStamp().trim())) {
									key = key + item.getUrl().trim();
									value = value + item.getStamp().trim();
									value = "authc,perms[" + value + "]";
									if(!map.containsKey(key)) map.put(key, value);
								}
							}
						}else {
							key = url + "/**";
							value = "authc,roles[developer]";
							map.put(key, value);
						}
						break;
					default:
						for(Operation item:butList) {
							key = url;
							value = mark;
							if(!"button".equals(item.getStamp())) {
								key = key + item.getUrl();
								value = value + item.getStamp();
								value = "authc,perms[" + value + "]";
								if(!map.containsKey(key)) map.put(key, value);
							}
						}
				}
			}
		}*/
		//map.put("/user.jsp", "authc,roles[user]");
		//map.put("/admin.jsp", "authc,roles[admin]");
		//map.put("/list.jsp", "user");
		//对shiro来说，/function和/function/是两个不同的url请求
		map.put("/**", "authc");
		//map.put("/**", "authc");
		
		return map;
	}
	
}
